package coreUtils

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
)

func Post(uri string, params map[string]any) (string, error) {
	form := url.Values{}
	for key, value := range params {
		form.Add(key, fmt.Sprintf("%v", value))
	}

	resp, err := http.PostForm(uri, form)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}

	return string(body), nil
}

func Get(uri string) (string, error) {
	resp, err := http.Get(uri)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	return string(body), nil
}
